﻿using DocumentFormat.OpenXml.Lite.Core.Interfaces;
using DocumentFormat.OpenXml.Lite.Core.Office;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DocumentFormat.OpenXml.Lite.Core.DocumentFS
{
    public class File
    {
        public string Name { get; set; }
        public Directory Parent { get; set; }
        public ISerializable Object { get; internal set; }

        public string XmlName
        {
            get
            {
                return Name.Substring(Guid.Empty.ToString().Length + 2);
            }
        }

        private File(string name, ISerializable obj)
        {
            this.Name = name;
            this.Object = obj;
        }

        public File(string name, string path, ISerializable obj)
            : this(name, obj)
        {
            Parent = DocumentFS.GetDirectory(path);
        }

        public File(string name, Directory directoy, ISerializable obj)
            : this(name, obj)
        {
            Parent = directoy;
        }

        public string GetPath()
        {
            Directory dir = Parent;
            string path = string.Empty;
            while (dir.Name != DocumentFS.Root.Name)
            {
                path = dir.Name + "/" + path;
                dir = dir.Parent;
            }
            path = DocumentFS.Root.Name + path;
            return path + Name;
        }

        public string GetXmlPath()
        {
            return GetPath().Substring(Guid.Empty.ToString().Length + DocumentFS.Root.Name.Length + 1);
        }
    }
}
